package com.winglish.as3.utils 
{
	import flash.display.DisplayObjectContainer;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.text.TextField;
	
	/**
	 * ...
	 * @author charmjin
	 */
	public class ObjectUtil 
	{
		
		public function ObjectUtil() 
		{
		}
		
		/**
		 * 무비클립 안에 있는 심볼들.(컴포넌트 미포함)
		 * @param	container
		 * @param	indentString
		 * @return
		 */
		static public function traceDisplayList(container:DisplayObjectContainer, indentString:String = ""):Array 
		{ 
			var child:DisplayObject; 
			var arr:Array = new Array();
			try{
				for (var i:uint=0; i < container.numChildren; i++) 
				{ 
					child = container.getChildAt(i); 
					if(child is MovieClip || child is SimpleButton || child is TextField) arr.push(child.name);
					if (container.getChildAt(i) is MovieClip) 
					{ 
						var subArr:Array = traceDisplayList(DisplayObjectContainer(child), indentString + "  -> "); 
						for (var j:int = 0; j < subArr.length; j++) {
							arr.push(child.name + "." + subArr[j]);
						}
					} 
				}
			}catch (e:Error) {
				trace("container.numChildren = 0");
			}
			return arr;
		}
		
		/**
		 * 무비클립 안에 있는 컴포넌트들.(기본 심볼 포함)
		 * @param	container
		 * @param	indentString
		 * @return
		 */
		static public function traceDisplayControlList(container:DisplayObjectContainer, indentString:String = ""):Array 
		{ 
			var child:DisplayObject; 
			var arr:Array = new Array();
			try{
				for (var i:uint=0; i < container.numChildren; i++) 
				{ 
					child = container.getChildAt(i); 
					if (container.getChildAt(i) is MovieClip) {
						var subArr:Array = traceDisplayControlList(DisplayObjectContainer(child), indentString + "    ") 
						for (var j:int = 0; j < subArr.length; j++) {
							arr.push(child.name + "." + subArr[j]);
						}
					}else if (container.getChildAt(i) is DisplayObjectContainer){ 
						arr.push(child.name);
					}else if (container.getChildAt(i) is SimpleButton || container.getChildAt(i) is TextField) {
						arr.push(child.name);
					}
				} 
			}catch (e:Error) {
				trace("container.numChildren = 0");
			}
			return arr;
		}
	}
}